﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;

namespace WMI.NET.CIM
{
    /// <summary>
    /// The CIM_SoftwareElement class decomposes a CIM_SoftwareFeature object into a set of individually manageable or deployable parts for a particular platform. A software element's platform is uniquely identified by its underlying hardware architecture and operating system.
    /// As such, to understand the details of how the functionality of a particular software feature is provided on a particular platform, the CIM_SoftwareElement objects referenced by CIM_SoftwareFeatureSoftwareElements associations are organized in disjoint sets based on the TargetOperatingSystem property. A CIM_SoftwareElement object captures the management details of a part or component in one of four states characterized by the SoftwareElementState property.
    /// </summary>
    public class CIM_SoftwareElement : CIM_LogicalElement
    {

        private string _BuildNumber;
        private string _CodeSet;
        private string _IdentificationCode;
        private string _LanguageEdition;
        private string _Manufacturer;
        private string _OtherTargetOS;
        private string _SerialNumber;
        private string _SoftwareElementID;
        private Nullable<UInt16> _SoftwareElementState;
        private Nullable<UInt16> _TargetOperatingSystem;
        private string _Version;

        /// <summary>
        /// Internal identifier for the compilation of this software element.
        /// </summary>
        public string BuildNumber { get { return _BuildNumber; } }

        /// <summary>
        /// Code set used by the software element.
        /// </summary>
        public string CodeSet { get { return _CodeSet; } }

        /// <summary>
        /// Manufacturer's identifier for the software element, often a stock-keeping unit (SKU) or part number.
        /// </summary>
        public string IdentificationCode { get { return _IdentificationCode; } }

        /// <summary>
        /// Language edition of the software element. The language codes defined in ISO 639 should be used. Where the software element represents multilingual or international versions of a product, the string "multilingual" should be used.
        /// </summary>
        public string LanguageEdition { get { return _LanguageEdition; } }

        /// <summary>
        /// Manufacturer of the software element.
        /// </summary>
        public string Manufacturer { get { return _Manufacturer; } }

        /// <summary>
        /// Manufacturer and operating system type for a software element when the TargetOperatingSystem property has a value of 1 ("Other"). When the TargetOperatingSystem property has a value of 1, this property must have a non-null value. For all other TargetOperatingSystem values, this property is null.
        /// </summary>
        public string OtherTargetOS { get { return _OtherTargetOS; } }

        /// <summary>
        /// Serial number of the software element.
        /// </summary>
        public string SerialNumber { get { return _SerialNumber; } }

        /// <summary>
        /// Identifier for the software element. It is designed to be used in conjunction with other keys to create a unique representation of this CIM_SoftwareElement.
        /// </summary>
        public string SoftwareElementID { get { return _SoftwareElementID; } }

        /// <summary>
        /// State of a software element.
        /// </summary>
        public Nullable<UInt16> SoftwareElementState { get { return _SoftwareElementState; } } //TODO enum

        /// <summary>
        /// Operating system environment. The value of this property does not ensure binary executability, more information is needed. The operating system version must be specified using the operating system version check. Also needed, is the architecture on which the operating system runs. The combination of these constructs allows the provider to clearly identify the level of operating system required for a particular software element.
        /// </summary>
        public Nullable<UInt16> TargetOperatingSystem { get { return _TargetOperatingSystem; } } //TODO enum

        /// <summary>
        /// Version of the operation.
        /// The version of the operation should be in one of the following forms:
        ///    major.minor.revision
        /// </summary>
        public string Version { get { return _Version; } }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public CIM_SoftwareElement(ManagementBaseObject mbo)
            : base(mbo)
        {
            _BuildNumber = mbo.GetStringValue("BuildNumber");
            _CodeSet = mbo.GetStringValue("CodeSet");
            _IdentificationCode = mbo.GetStringValue("IdentificationCode");
            _LanguageEdition = mbo.GetStringValue("LanguageEdition");
            _Manufacturer = mbo.GetStringValue("Manufacturer");
            _OtherTargetOS = mbo.GetStringValue("OtherTargetOS");
            _SerialNumber = mbo.GetStringValue("SerialNumber");
            _SoftwareElementID = mbo.GetStringValue("SoftwareElementID");
            _SoftwareElementState = mbo.GetUshortValue("SoftwareElementState");
            _TargetOperatingSystem = mbo.GetUshortValue("TargetOperatingSystem");
            _Version = mbo.GetStringValue("Version");
        }

    }
}
